package com.simple.crawler.constant;

import com.simple.crawler.utils.ReflectUtils;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;

public enum HttpMethod {
    GET(HttpGet.METHOD_NAME, HttpGet.class, "GET请求"),
    POST(HttpPost.METHOD_NAME, HttpPost.class, "POST请求"),
    DELETE(HttpDelete.METHOD_NAME, HttpDelete.class, "DELETE请求");

    private String value;

    private Class<? extends HttpRequestBase> requestType;

    private String msg;

    HttpMethod(String value, Class<? extends HttpRequestBase> requestType, String msg) {
        this.value = value;
        this.requestType = requestType;
        this.msg = msg;
    }

    public String getValue() {
        return value;
    }

    public Class<? extends HttpRequestBase> getRequestType() {
        return requestType;
    }

    public String getMsg() {
        return msg;
    }

    public static <T extends HttpRequestBase> T createRequest(HttpMethod method, String url) {
        return (T) ReflectUtils.getInstance(method.requestType, url);
    }

}
